/**
 * 导出一些常用的函数
 * @type {{}}
 */
var fs = require('fs'), util = require('util');

module.exports = {
    addController: function(generator, controller_name){
        var source = generator.templatePath('../../app/templates/controllers/_controller.js');
        var dest = generator.destinationPath('js/controllers/'+controller_name + '.js');
        generator.template(source, dest, {controller: controller_name});
        //添加到控制里面
        var idx_file = generator.destinationPath('js/controllers/index.js');
        var content = generator.readFileAsString(idx_file);
        fs.writeFileSync(idx_file, content.replace(']',util.format(",'./%s']", controller_name)));
    }, addView: function(generator, view_name){
        var source = generator.templatePath('../../app/templates/_view_index.html');
        var dest = generator.destinationPath(util.format('js/views/%s', view_name));
        generator.copy(source, dest);
    }
};